<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>
        .cc1 {
            width: 100px;
            height: 100px;
            background-color: red;
        }
        .cc2{
            background-color: green;
        }

    </style>
</head>
<body>

<!--<div class="cc1 xx xx2" id="d1" onclick="f1(this);">-->
<div class="cc1 xx xx2" id="d1">

</div>


<script>
    var divEle = document.getElementById('d1');
    divEle.onclick = function () {
        // divEle.style.backgroundColor = 'purple';
        this.style.backgroundColor = 'purple';
    }
    // function f1(ths) {
    //     // var divEle = document.getElementById('d1');
    //     ths.style.backgroundColor = 'purple';
    // }


</script>
</body>
</html>